<template>
  <div class="da">
    <van-search v-model="value" shape="round" placeholder="请输入搜索关键词" @focus="zhuan" />
    <!-- 轮播图 -->
    <Swiper :banner="banner"></Swiper>
    <!-- //图标导航 -->
    <Grid :channel="channel"></Grid>
    <!-- pinpaizhizaoshangzhigong直供  -->
    <h1>品牌制造商直供</h1>
    <ul class="pinpai">
      <li v-for="item in brandList" :key="item.id">
        <img :src="item.pic_url" alt="" />
        <span>
          {{ item.name }}
        </span>
        <span class="cc"> ￥{{ item.floor_price }} </span>
      </li>
    </ul>
    <!-- 新品 -->
    <shoufa :newGoodsList="newGoodsList"></shoufa>
    <!-- 人气推荐 -->
    <hotGoodsList :hotGoodsList="hotGoodsList"></hotGoodsList>
    <!-- 分类数组 -->
    <categoryList :categoryList="categoryList"></categoryList>
  </div>
</template>

<script>
import Vue from "vue";
import { Search } from "vant";
import { gethomedata } from "@/api/homeapi";
import Swiper from "@/components/swivpi.vue";
import Grid from "@/components/grid.vue";
import shoufa from "@/components/shoufa.vue";
import hotGoodsList from "@/components/hotGoodsList.vue";
import categoryList from "@/components/categoryList.vue";
Vue.use(Search);

export default {
  name: "",
  data() {
    return {
      value: "",
      banner: [],
      channel: [],
      brandList: [],
      newGoodsList: [],
      hotGoodsList: [],
      categoryList: [],
      categoryList1: [],
    };
  },
  mounted() {
    // 异步的话需要在生命周期里面去掉一下
    this.getdata();
  },
  components: { Swiper, Grid, shoufa, hotGoodsList, categoryList },
  methods: {
    zhuan() {
      this.$router.push("/search");
    },
    async getdata() {
      let res = await gethomedata();
      console.log(res);
      this.banner = res.data.banner;
      this.channel = res.data.channel;
      this.brandList = res.data.brandList;
      this.newGoodsList = res.data.newGoodsList;
      this.hotGoodsList = res.data.hotGoodsList;
      this.categoryList = res.data.categoryList;
    },
  },
};
</script>
<style lang="less" scoped>
.da {
  width: 100%;

  h1 {
    text-align: center;
    font-size: 24px;
    margin-top: 10px;
    margin-bottom: 10px;
  }

  .pinpai {
    margin: 0 auto;
    width: 100%;
    height: 300px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;

    // margin-left: 10px;
    box-sizing: border-box;

    li {
      width: 45%;
      height: 45%;
      display: flex;
      flex-direction: column;
      //   align-items: center;
      position: relative;

      img {
        float: left;
        width: 100%;
        height: 100%;
      }

      span {
        position: absolute;
        left: 10%;
        // width: 200px;
        top: 15%;
        // display: block;
        // float: left;
        font-size: 16px;
      }

      .cc {
        position: absolute;
        left: 20%;
        top: 30%;
      }
    }
  }
}
</style>